/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Factory.DAO.MySQL;

import DatabaseConnection.DBConnectionFactory;
import Factory.DAO.LogDefDAO;
import Factory.DAOFactory;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Patrick
 */
public class MySQLLogDefDAO extends LogDefDAO{

    @Override
    public int getLogDefID(String LogDefName) {
        try {
            // TODO code application logic here
            DBConnectionFactory myFactory = DBConnectionFactory.getInstance(DAOFactory.MYSQL);
            int id;
            try (Connection conn = myFactory.getConnection()) {
                PreparedStatement pstmt = conn.prepareStatement("select idlogdef from logdef where name = ?");
                pstmt.setString(1, LogDefName);
                ResultSet rs = pstmt.executeQuery();
                id = -1;
                while(rs.next()){
                    id = rs.getInt("idlogdef");
                }
            }
            return id;
        } catch (SQLException ex) {
            Logger.getLogger(MySQLUserDefDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return -1;
        
    }

    @Override
    public String getLogDefName(int LogDefID) {
        try {
            // TODO code application logic here
            DBConnectionFactory myFactory = DBConnectionFactory.getInstance(DAOFactory.MYSQL);
            String name;
            try (Connection conn = myFactory.getConnection()) {
                PreparedStatement pstmt = conn.prepareStatement("select name from logdef where idlogdef = ?");
                pstmt.setInt(1, LogDefID);
                ResultSet rs = pstmt.executeQuery();
                name = null;
                while(rs.next()){
                    name = rs.getString("name");
                }
            }
            return name;
        } catch (SQLException ex) {
            Logger.getLogger(MySQLUserDefDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }
    
}
